<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
BoardDao boardDao = new BoardDaoImpl();
Map mapBoard = boardDao.findBoard();
TopicDao topicDao = new TopicDaoImpl();
UserDao userDao = new UserDaoImpl();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#apDiv1 {
	position: absolute;
	left: 1px;
	top: 1px;
	width: 800px;
	height: 50px;
	z-index: 1;
	text-align: center;
	font-weight: bold;
	font-size: 36px;
	color: #F00;
}
#apDiv2 {
	position: absolute;
	left: 1px;
	top: 51px;
	width: 800px;
	height: 25px;
	z-index: 2;
	font-size: 12px;
	background-color: #e0f0f9;
	color: #004c7d;
}
#apDiv3 {
	position: absolute;
	left: 1px;
	top: 76px;
	width: 800px;
	height: 500px;
	z-index: 3;
	color: #000;
	text-align: center;
}
#apDiv3 table tr td {
	font-size: 12px;
	color: #004c7d;
	text-align: left;
}
</style>
</head>

<body>
<div id="apDiv1">校园BBS系统</div>

<%
if(session.getAttribute("user")==null){
 %>
<div id="apDiv2">您尚未 <a href="login.jsp">登录</a>  | <a href="reg.jsp">注册</a></div>
<%
}else{
	User loginUser = (User)session.getAttribute("user");
%>
<div id="apDiv2">您好，<jsp:getProperty property="userName" name="user" scope="session"/>  | <a href="manage/doLogout.jsp">登出</a></div>
<%
}
 %>
<div id="apDiv3">
  <table width="800" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="2">论坛</td>
      <td width="42">主题</td>
      <td width="392">最后发表</td>
    </tr>
    					<!-- 主板块 -->
    <%
    List listMainBoard = (List)mapBoard.get(new Integer(0));
    for(int i = 0 ; i < listMainBoard.size() ; i++ ){
    	Board mainBoard = ((Board)listMainBoard.get(i));
     %>
    <tr>
      <td colspan="4"><%=mainBoard.getBoardName() %></td>
    </tr>
    					<!-- 子版块 -->
    <%
    List listSonBoard = (List)mapBoard.get(new Integer(mainBoard.getBoardId()));
    for(int j = 0;j<listSonBoard.size(); j++ ){
    	Board sonBoard = (Board)listSonBoard.get(j);
    	Topic topic = new Topic();
    	User user = new User();
    	int boardId = sonBoard.getBoardId();
    	List listTopic = topicDao.findListTopic(1,boardId);
    	if(listTopic!=null&&listTopic.size()>0){
    		topic = (Topic)listTopic.get(0);
    		user = userDao.findUser(topic.getUid());
    	}
     %>
    <tr>
      <td width="24">&nbsp;</td>
      <td width="342">
      <a href="list.jsp?page = 1&boardId=<%=boardId %>">
      <%=sonBoard.getBoardName() %>
      </a>
      </td>
      <th>
      	<span>
      		<a href="detail.jsp?page=1&boardId=<%=boardId %>&topicId=<%=topic.getTopicId() %>"><%=topic.getTitle() %></a>
      	</span>
      	<br />
      	<span><%=user.getUName() %></span>
      	<span class="gray">[<%=topic.getPublishTime() %>]</span>
      </th>
    </tr>
    <%
    	}
    } 
    %>
  </table>
</div>

</body>
</html>

